package com.ocom.payconfig.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ocom.common.entity.pay.EntityAppConfig;
import com.ocom.common.enums.DataSourceEnum;
import com.ocom.common.enums.MasterSlaveEnum;
import com.ocom.mysql.aspect.DataSourceAspect;
import com.ocom.payconfig.dao.IDaoAppConfig;
import com.ocom.payconfig.service.AppConfigService;
import org.springframework.stereotype.Service;


@Service
public class AppConfigServiceImpl extends ServiceImpl<IDaoAppConfig, EntityAppConfig> implements AppConfigService {


    @Override
    @DataSourceAspect(type= DataSourceEnum.MAIN_DB,isMaster = MasterSlaveEnum.SLAVE)
    public EntityAppConfig getAppConfig(Long companyId) {
        QueryWrapper<EntityAppConfig> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("com_id",companyId);
        queryWrapper.orderByDesc("update_time");
        queryWrapper.last("limit 1");
        EntityAppConfig entityAppConfig =  this.getOne(queryWrapper);
        if(entityAppConfig==null ) return new EntityAppConfig();
        return entityAppConfig;
    }
}
